package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl;

import java.util.HashMap;

import com.seanchenxi.gwt.wordpress.domain.model.Page;
import com.seanchenxi.gwt.wordpress.domain.model.PageStatus;

public class PageImpl extends ContentImpl implements Page{
	
	/**
	 * Generated id
	 */
	private static final long serialVersionUID = -9082415499772681258L;
	static final String[] PARENT_ID = {"wp_page_parent_id","page_parent_id"};
	static final String PAGE_STATUS = "page_status";	
	static final String PARENT_TITLE = "wp_page_parent_title";
	static final String PAGE_ORDER = "wp_page_order";
	static final String PAGE_TEMPLATE = "wp_page_template";
	
	public PageImpl() {
		super();
		set(POST_TYPE, "page");
	}

	public PageImpl(HashMap<String, Object> properties) {
		super(properties);
		set(POST_TYPE, "page");
	}

	@Override
	public PageStatus getPageStatus() {
		return get(PAGE_STATUS);
	}

	@Override
	public void setPageStatus(PageStatus page_status) {
		set(PAGE_STATUS, page_status);
		
	}

	@Override
	public String getParentTitle() {
		return get(PARENT_TITLE);
	}

	@Override
	public void setParentTitle(String wp_page_parent_title) {
		set(PARENT_TITLE, wp_page_parent_title);
		
	}

	@Override
	public int getPageOrder() {
		return get(PAGE_ORDER);
	}

	@Override
	public void setPageOrder(int wp_page_order) {
		set(PAGE_ORDER, wp_page_order);
		
	}

	@Override
	public String getPageTemplate() {
		return get(PAGE_TEMPLATE);
	}

	@Override
	public void setPageTemplate(String wp_page_template) {
		set(PAGE_TEMPLATE, wp_page_template);
	}

	@Override
	public int getParentId() {
		return get(ParentIdKey());
	}

	@Override
	public void setParentId(int page_parent_id) {
		set(ParentIdKey(), page_parent_id);
	}
	
	
	protected String ParentIdKey(){
		for(String parentIdKey : PARENT_ID){
			if(getPropertyNames().contains(parentIdKey)){
				return parentIdKey;
			}
		}
		return PARENT_ID[0];
	}
	
}
